package com.sicheng.algorithm.recursive;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author zsc
 * @version 1.0
 * @date 2021/9/24 10:10
 */
public class Perm {
    public static void main(String[] args) {

        Perm perm = new Perm();
        int n = new Scanner(System.in).nextInt();
        int sum = new Scanner(System.in).nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = i + 1;
        }

        perm.perm(nums);
        for (List<Integer> list : perm.res) {
            int[][] dp = new int[n][n];
            for (int i = 0; i < n; i++) {
                dp[0][i] = list.get(i);
            }

            for (int i = 1; i < n; i++) {
                for (int j = 0; j < n - 1; j++) {
                    dp[i][j] = dp[i - 1][j] + dp[i - 1][j + 1];
                    if (dp[n-1][0]==sum)
                        System.out.println(list);
                }
            }
        }

        System.out.println(perm.res);
    }

    private List<List<Integer>> res;
    private ArrayDeque<Integer> path;
    private int total;

    public void perm(int[] list) {
        if (list == null || list.length < 1)
            return;

        res = new ArrayList<>();
        path = new ArrayDeque<>();
        perm(list, 0);
        System.out.println(total);
    }


    public void perm(int[] list, int start) {
        if (path.size() == list.length) {
            total++;
            res.add(new ArrayList<>(path));
            return;
        }
        for (int i = start; i < list.length; i++) {
            if (path.contains(list[i]))
                continue;
            path.addLast(list[i]);
            perm(list, start);
            path.removeLast();
        }


    }
}
